ASSEMBLY LANGUAGE STEP BY STEP, SECOND EDITION By Jeff Duntemann K7JPD www.duntemann.com README file for the book CD Last Updated 12/12/1999 This CD contain software copyrighted by its respective authors; see the license files for the individual software tools. All other material on this CD (c) 2000 by Jeff Duntemann. OVERVIEW This book covers both DOS and Linux assembly language, so the CD has been divided into two major sections in two subdirectories: ForDos and ForLinux. All materials pertinent to the DOS discussions in the book are under the ForDos subdirectory; all materials pertinent to Linux are under ForLinux. SOFTWARE ACKNOWLEDGEMENTS All software included here is included by permission of the authors, whom I graciously thank for the privilege. Check the home pages for the various tools to catch the latest updates. This book was published in early 2000 and may be in print for a long time. Do NOT assume that the software pressed onto the CD in January 2000 will be current when you buy the book. The first edition of this book was in print from 1992 to 2000! * NASM By NASM team leader Julian "Jules" Hall, plus team members Simon Tatham, H. Peter Anvin, John Fine, Kendall Bennet, Gary Clark, and Andrew Crabtree: http://www.web-sites.co.uk/nasm/ * NASM-IDE By Robert Anderton: http://www.inglenook.co.uk/nasmide/ * ALINK By Anthony Williams: http://alink.home.dhs.org/ INSTALLATION There is no single "installation" utility. That's a Windows convention, and we're not dealing with Windows here. You have to set up your working directories manually, as in the bad old days. This should be obvious, but note well: You CANNOT work off the CD. NASM-IDE, in particular, writes to its .INI file, and you can't write to the CD. Copy everything you'll need off the CD into an appropriate place on your hard drive. DOS There's a directory under FORDOS called ASM. If you drag the ASM directory to a hard disk under Windows Explorer, it will copy everything you need off the CD to your hard disk. If you're working under DOS you'll need to use XCOPY to get the subdirectories. For simplicity's sake I just piled everything into that one ASM directory: NASM, NASM- IDE, ALINK, and all your source code. This isn't good practice if you're doing a lot of sophisticated work in assembly, but it'll do while you get your bearings. Once you begin doing "real" work you'll probably want to set up a more sophisticated directory scheme, but everybody has his or her own tastes for that and I won't presume to tell you what to do. There are separate directories for the tools under ASM, and one way to begin is to put those directories on your path. But once you get good enough to need to add some organization to your directories, you'll know what to do. Other odd notes: * The version of NASM I provide for DOS work is called NASM16.EXE. There are several versions, but this is the one for which I wrote and tested the example code, and the only one you'll find on the CD. * The NASM documentation is present in two forms, both in the FORDOS section. One is a single Postscript file, the other separate chapter files in HTML. I recommend printing it out and putting it in a binder. Once you get beyond the beginner stage you're going to have to digest that doc thoroughly. * The Alink linker (ALINK.EXE) requires that another file be either on your path or in your work directory before you can use the linker. This file is RSX.EXE. You don't have to run it; Alink runs it "behind the scenes" when you run Alink. * Make sure you read the CAUTIONS header at the end of this file if you're using Windows NT4. NASM-IDE has done some odd things for me when I had it on an NTFS file system under NT4. LINUX First of all, make SURE you know your way around Linux before you try programming for it in assembly. The book doesn't attempt to teach Linux, and if you've never used Linux before you're going to be completely lost. Get a couple of good books on it and study up for a week or two before you start programming. Books are beginning to appear for individual distributions in late 1999 and that trend will only continue. There are detailed instructions for installing NASM in Chapter 12. Read them and follow them EXACTLY. This involves rebuilding the assembler from source code, which I provide in the file nasm-0.98.tar. This is less scary than it sounds, but you really ought to be comfortable with the Linux file systems and common Linux commands before you attempt it. You don't need to scrounge a linker for Linux work; Linux comes with a linker and the gcc C compiler invokes it automatically. This may sound weird but get used to it: You link by running a C compiler. There's a full explanation in Chapter 12. I recommend that you use EMACS for your editor. EMACS is installed with every copy of Linux I've ever seen, and there are some good books about it. But note that I do not provide an editor for Linux work. I have placed every example program for Linux in its own subdirectory, and I recommend copying all these subdirectories to a place on your hard drive. Placing each project in a separate directory is a Unix custom, and this allows the make file to have the same name for all projects. (The name of the make file is simply "makefile.") Again, you need to read Chapter 12 completely before trying to do any assembly programming for Linux. It's a lot more involved than DOS, which is a mere shadow of the operating system that Linux is. JLIST10 There is a little utility I wrote years ago in Borland Pascal present on the CD: JLIST10.EXE. It's a LaserJet listings printer, and it can create nice printouts from any text file. Just type the name of the file you want to print (the filename can include wildcards) on the command line after the utility's name: JLIST10 *.ASM JLIST10 EAT5.LST etc. Although I wrote JLIST10 in Pascal, it would make an interesting "term project" to duplicate it in assembly, particularly for Linux. ERRATA I will try to maintain a current list of typos and such on my personal home page: www.duntemann.com. I change it often, so I won't give any specific URLs within the site. Just go to www.duntemann.com and look for my assembly language section. CAUTIONS There are some weirdnesses involved in using NASM-IDE in a DOS box under Windows NT4, especially with Service Pack 4 and later. When you exit NASM-IDE, it deletes its .INI file and you have to re-copy it from archive. The author is working on it; check the NASM-IDE Web site for updates: http://www.inglenook.co.uk/nasmide/ Also, in an NT4 DOS box the NASM-IDE include directory field in the Options|Directories menu item doesn't seem to apply its path to the assemble operation. This problem occurs on NTFS file systems only, as far as I can tell. If you're running NT4 but working on a FAT file system you shouldn't run into it. Every NT4 service pack seems to make NT more hostile to DOS apps like NASM-IDE. The DOS emulation under NT4 is just that: Emulation. It isn't "really" DOS at all. To do DOS work I recommend using Windows 95 or 98 or actual DOS.